package com.hanamaki.appiumstudy;

import io.appium.java_client.android.AndroidDriver;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.TimeUnit;

public class AppiumDemo01 {

    public static void main(String[] args) {

        /* 1.配置启动所需要的信息 */
        DesiredCapabilities capabilities = new DesiredCapabilities();
        /* 1. 平台 */
        capabilities.setCapability("platformName","Android");
        /* 2. 主机 */
        capabilities.setCapability("deviceName","127.0.0.1:62001");
        /* 3. 想要启动的软件的包名 */
        capabilities.setCapability("appPackage","com.iBookStar.activityOff");
        /* 4. 想要启动的软件的类名 */
        capabilities.setCapability("appActivity", "com.iBookStar.activityOff.Splash");

        /* 5. 启动*/
        URL url = null;
        try {
            url = new URL("http://127.0.0.1:4723/wd/hub");
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
        AndroidDriver<WebElement> driver = new AndroidDriver<WebElement>(url, capabilities);

        /* 隐式等待 */
        WebDriver.Timeouts timeouts = driver.manage().timeouts();
        timeouts.implicitlyWait(30, TimeUnit.SECONDS);

        /* 在 appium 中通过元素定位的方式   id  =  com.iBookStar.activityOff:id/go */
        /* 来点击 开始体验 */
        driver.findElement(By.id("com.iBookStar.activityOff:id/go")).click();

    }
}
